<script type="text/javascript" src="<?php echo $baseurl.'public/theme/manage/'?>js/jquery.tablednd.js"></script>
<script type="text/javascript" src="<?php echo $baseurl.'public/theme/manage/'?>js/jqueryTableDnDArticle.js"></script>
<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="<?php echo $baseurl?>">Trang chủ</a> <span class="divider">/</span></li>
        <li class="active">Danh sách nhà hàng</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Quản lý danh sách nhà hàng</h1> <span></span>
</div>
<div class="maincontent">
    <div class="contentinner">    
    
        <?php $attr = array('class' => 'stdform','id' => 'form-list'); echo form_open('', $attr);?>
        <div id="dyntable_length" class="dataTables_length  content-dashboard">
        <input type="hidden" name="check-delete" value="1" />
        
            <a href="<?php echo $baseurl.'manage/restaurant/add-restaurant'?>" class="btn"><i class="icon-plus"></i> Thêm mới</a>
            <button class="btn" type="button" onclick="deleteall()"><i class="icon-remove"></i> Xóa đã chọn</button>
            Gợi ý: Nhấn chuột và kéo thả các dòng để sắp xếp vị trí.
        </div>
    	<table class="table table-bordered" id="table-1">
            <colgroup>
                <col class="con0" />
                <col class="con1" />
                <col class="con0" />
                <col class="con1" />
                <col class="con0" />
                <col class="con1" />
            </colgroup>
            <thead>
                <tr>
                	<th class="centeralign" style="width: 5%;"><input type="checkbox" class="checkall" /></th>
                    <!-- <th style="width: 8%;">STT</th> -->
                    <th style="width: 120px">Logo Nhà hàng</th>
                    <th>Tên nhà hàng</th>
                    <th>Khu vực - thành phố</th>
                    <th>Danh mục</th>
					<th>Đánh giá</th>
                    <th class="centeralign" style="width: 10%">Tác vụ</th>
                </tr>
            </thead>
            <tbody>
            <?php if(!in_array($data, array(null, '', '0'))):?>
            <?php foreach($data AS $el=>$le):?>
                <tr id="<?php echo $le->id?>">
                	<td class="centeralign"><input name="checkboxs[]" id="<?php echo $le->id?>" type="checkbox" value="<?php echo $le->id?>" /></td>
                    <!-- <td>1</td> -->
                    <td style="text-align: center;"><img src="<?php echo $imgbase.$le->logo?>" style="width: 120px;height: 50px" onError="this.src='<?php echo $baseurl."public/theme/manage/img/gray_jean.png";?>'" /></td>
                    <td><?php echo $le->name?></td>
                    <td>
                        <?php if(!in_array($le->zone, array(null, '', '0'))):?>
                            <?php $c = sizeof($le->zone); $s = 0; foreach($le->zone AS $ell=>$lle):?>
                            <!-- <a href="<?php echo $baseurl.'manage/restaurant/order-restaurant-zone/'.$lle->id?>"> -->
                            <a>
                                <?php echo $lle->title?>
                            </a>
                            <?php $s++; if($s < $c){echo ', ';}?>
                            <?php endforeach;?>
                        <?php else: ?>
                        Chờ cập nhật
                        <?php endif;?>
                    </td>
                    <td>
                        <?php if(!in_array($le->categories, array(null, '', '0'))):?>
                            <?php $cs = sizeof($le->categories); $ss = 0;  foreach($le->categories AS $ell=>$lle):?>
                            <!-- <a href="<?php echo $baseurl.'manage/restaurant/order-restaurant-categories/'.$lle->id?>"> -->
                            <a>
                                <?php echo $lle->title;?>
                            </a>
                            <?php $ss++; if($ss < $cs){echo ', ';}?>
                            <?php endforeach;?>
                        <?php else: ?>
                        Chờ cập nhật
                        <?php endif;?>
                    </td>
					 <td>
					  <?php echo $le->review ? $le->review : '0'; echo '<span class="icon-star"></span> / '.$le->count_review. '<span class="iconsweets-user"></span>';?>
					 </td>
                    <td class="centeralign">
                        <a href="<?php echo $baseurl.'manage/restaurant/edit-restaurant/'.$le->id?>" class=""><span class="icon-edit"></span></a>
                        <a href="<?php echo $baseurl.'manage/restaurant/delete-restaurant/'.$le->id?>" class="delete-a"><span class="icon-trash"></span></a>   
                    </td>
                </tr>
            <?php endforeach;?>
            <?php endif?>
            </tbody>
        </table>
        <div class="dataTables_info" id="dyntable_info">
            <div class="pagination">
                <?php echo $this->pagination->create_links();?> 
            </div>
        </div>
        </form>
    </div>
    
</div>
<div id="show_msg">
        msg
    </div>
<style>
.table th, .table td {
vertical-align: middle !important;
}
.tDnD_whileDrag{
    background: #ddd;
}
#show_msg{
    width: 200px;top: 5%;right: 5px;position: fixed;background: #F25C5C;padding: 12px 5px;border-radius: 5px;border: 1px solid #B84B4B;box-shadow: 1px 2px 6px #666;color: #FFF;display: none;text-shadow: 0px 1px 1px #DDD;z-index: 999999
}
</style>
<script type="text/javascript">
$(document).ready(function() {
    $("#table-1").tableDnD({
        onDrop: function(table, row) {
            var rows = table.tBodies[0].rows;
            var _id = '';
            for (var i=0; i<rows.length; i++) {
                _id += rows[i].id+",";
            }
            if(_id)
            {
                $.ajax({
                    type: 'get',
                    url: '<?php echo site_url().'sort-label'?>',
                    data:({arr: _id}),
                    success: function(_data)
                    {
                        if(_data == 'ok')
                        {
                            $("#show_msg").show().html('Cập nhật thứ tự thành công');
                            setTimeout(function()
                            {
                                $("#show_msg").hide();
                            }, 1000);
                            
                        }
                    }
                });   
            }
        }
    });
    
});
</script>